// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { _decorator, Component, tween, EventKeyboard, macro, systemEvent, AudioSource, Vec3, SystemEventType, log } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Player')
export default class Player extends Component {

    @property
    public jumpHeight: number = 0;
    @property
    private jumpDuration: number = 0;
    private currentPos: Vec3 = new Vec3(0,0,0);


    @property(AudioSource)
    jumpAudioSource: AudioSource = null!;


    runJumpAction() {
        let jumpUp = tween().by(this.jumpDuration, { position: new Vec3(0, this.jumpHeight, 0) }, { easing: 'sineOut'});
        let jumpDown = tween().by(this.jumpDuration, { position: new Vec3(0, -this.jumpHeight, 0) }, { easing: 'sineIn'});
        let tw = tween().sequence(jumpUp, jumpDown);
        return tw.repeatForever();
    }

    getCurPosition(){
        Vec3.add(this.currentPos, this.node.getPosition(), this.node.getParent()!.getPosition());
        return this.currentPos;
    }


    start() {
        let jumpAction = this.runJumpAction();
        tween(this.node).then(jumpAction).start();
    }
    
    update(dt: number){

    }
}
